package cn.cs.yangtai.service.impl;

import cn.cs.yangtai.entity.Classification;
import cn.cs.yangtai.entity.Orderdetails;
import cn.cs.yangtai.entity.vo.OrderdetailsVo;
import cn.cs.yangtai.entity.vo.PageResult;
import cn.cs.yangtai.mapper.OrderdetailsMapper;
import cn.cs.yangtai.service.OrderdetailsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * (Orderdetails)表服务实现类
 *
 * @author makejava
 * @since 2024-12-12 09:22:27
 */
@Service("orderdetailsService")
public class OrderdetailsServiceImpl implements OrderdetailsService {
    @Resource
    private OrderdetailsMapper orderdetailsMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param dId 主键
     * @return 实例对象
     */
    @Override
    public OrderdetailsVo queryById(Integer dId) {
        return this.orderdetailsMapper.queryById(dId);
    }

    @Override
    public List<OrderdetailsVo> queryByOrderId(Integer orderId) {
        return orderdetailsMapper.queryByOrder(orderId);
    }

    /**
     * 分页查询
     *
     * @param cuttentPage 本页
     * @param pageSize    分页大小
     * @return 查询结果
     */
    @Override
    public PageResult<OrderdetailsVo> queryByPage(Integer cuttentPage, Integer pageSize) {
        PageHelper.startPage(cuttentPage,pageSize);
        Page<OrderdetailsVo> orderdetails =orderdetailsMapper.queryAllByLimit(new Page<>());
        return PageResult.restPage(orderdetails);
    }

    /**
     * 新增数据
     *
     * @param orderdetails 实例对象
     * @return 实例对象
     */
    @Override
    public Orderdetails insert(Orderdetails orderdetails) {
        this.orderdetailsMapper.insert(orderdetails);
        return orderdetails;
    }

    /**
     * 修改数据
     *
     * @param orderdetails 实例对象
     * @return 实例对象
     */
    @Override
    public OrderdetailsVo update(Orderdetails orderdetails) {
        this.orderdetailsMapper.update(orderdetails);
        return this.queryById(orderdetails.getDId());
    }

    /**
     * 通过主键删除数据
     *
     * @param dId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer dId) {
        return this.orderdetailsMapper.deleteById(dId) > 0;
    }
}
